package com.qf.day08.homework.fight;

import java.util.Random;

public class BattleManger {

    /**
     * 组队pik
     * 每队三个选手
     * 如果某一队的所有选手都阵亡，游戏结束
     * @param team1
     * @param team2
     */
    public static void teamPk(Fightable[] team1,Fightable[] team2){

    }


    /**
     * 实现让两个 Fightable 对象进行pk，分出胜负
     * @param player1
     * @param player2
     */
    public static void pk(Fightable player1,Fightable player2){

        System.out.println("pk开始");

        int count = 1; // 代表回合数

        while ( player1.isAlive() && player2.isAlive() ){ // 如果两个玩家都或者，那么继续pk
            System.out.println("第"+(count++)+"回合:");
            //1. 让一个player攻击另外一个player
            Random random = new Random();
            int i = random.nextInt(2);
            if (i==0){
                // 让player1先攻击
                System.out.println("player1先攻击");
                player1.fight(player2);
                //2. 要不要打回去呢
                // 被打的玩家是不是已经挂了，没有挂掉，就打回去
                if (player2.isAlive()) {
                    System.out.println("player2后攻击");
                    player2.fight(player1);
                }else {
                    System.out.println("player2被打败了，游戏结束");
                }
            }else {
                // 让player2先攻击
                System.out.println("player2先攻击");
                player2.fight(player1);

                if (player1.isAlive()){
                    player1.fight(player2);
                }else {
                    System.out.println("player1被打败了，游戏结束");
                }
            }

            // 每个回合结束后，打印两个player的状态
            System.out.println(player1);
            System.out.println(player2);
        }

    }

}
